﻿using System;
using System.Collections.Generic;
using Epitech.Krisk.Kinect.Sensor.Tools;
using Microsoft.Research.Kinect.Nui;
using Microsoft.Xna.Framework;

namespace Epitech.Krisk.Kinect.Sensor.Gestures.Navigation
{
    public class NavigationGesture 
    {
        private float _trustIndex;
        private List<Vector3> _selectionJoint = new List<Vector3>();
        public event EventHandler<SelectionEventArgs> SelectionEvent;
        private DateTime _lastClick = DateTime.Now;
        public event Action<float> Click;


        public NavigationGesture(float trustIndex)
         {
             _trustIndex = trustIndex;
         }

        public void OnClick(float val)
        {
            Action<float> handler = Click;
            if (handler != null) handler(val);
        }

        public void AddJoint(Vector position)
        {
            var val = Convert.ToInt32((position.ToVector3X().Y + 0.2f)*10);
            _selectionJoint.Add(position.ToVector3X());
            SelectionEvent(this, new SelectionEventArgs(val, position.ToVector3X().Z));
        }

        public void PushClick(Joint hand, Joint shoulder)
        {
            var f = shoulder.Position.Z - hand.Position.Z;
            if (f > 0.400 && DateTime.Now.Subtract(_lastClick).Seconds > 2)
            {
                OnClick(f);
                _lastClick = DateTime.Now;
            }
        }
    }
}